package com.fm.parser.code;

import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CodeParser {
	protected static final String useful = "\\-0-9A-Za-z";
	protected static int whitespaceMin = 1;
	protected static int whitespaceMax = 1;
	private static final Pattern pattern = Pattern.compile("(?<need>" +
		"[" + useful + "]+" +
		"( {" + whitespaceMin + "," + whitespaceMax + "}[" + useful + "]+)?" +
		"( {" + whitespaceMin + "," + whitespaceMax + "}[" + useful + "]+)?" +
		"( {" + whitespaceMin + "," + whitespaceMax + "}[" + useful + "]+)?" +
		")" +
		"(  | ?([^" + useful + "]|$))");

	public static List<String> find(String test) {
		List<String> list = new LinkedList<>();
		Matcher m = pattern.matcher(test);
		while (m.find()) {
			list.add(m.group("need"));
		}
		return list;
	}
}
